<template>
    <cover-view class="tabbar" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}">
        <cover-view class="tabbar-item"
            v-for="(item, index) in list" 
            :key="index" 
            @click="tabbarChange(item.path)"
        >
            <cover-image class="item-img" :src="item.icon_a" v-if="current == index"></cover-image>
            <cover-image class="item-img" :src="item.icon" v-else></cover-image>
            <cover-view class="item-name" :class="{'tabbarActive': current == index}" v-if="item.text">{{item.text}}</cover-view>
        </cover-view>
    </cover-view>
	
</template>

<script>
export default {
    props: {
        current: String
    },
    data() {
        return {
            paddingBottomHeight: 0,  //苹果X以上手机底部适配高度
            list: [{
                    text: '首页',  
                    icon:'../../static/icon/sy.png',  //未选中图标
                    icon_a: '../../static/icon/home.png',  //选中图片
                    path: "../../pages/user/home/index",  //页面路径
                },{
                    text: '票夹',
                    icon: '../../static/icon/fp.png',
                    icon_a: '../../static/icon/fp1.png',
                    path: "../../pages/user/ticket/index",
                },{
				    text: ' ',
				    icon: '../../static/icon/sys.png',
				    icon_a: '../../static/icon/sys1.png',
				    path: "../../pages/user/scan/index",
				}
                ,{
                    text: '统计',
                    icon: '../../static/icon/tj.png',
                    icon_a: '../../static/icon/tj1.png',
                    path: '../../pages/user/statistics/index',
                },{
                    text: '我的',
                    icon: '../../static/icon/wd.png',
                    icon_a: '../../static/icon/my.png',
                    path: "../../pages/user/mine/index",
                },
            ]
        };
    },
    created() {
        let that = this;
        uni.getSystemInfo({
            success: function (res) {
                let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
                model.forEach(item => {
                    //适配iphoneX以上的底部，给tabbar一定高度的padding-bottom
                    if(res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
                        that.paddingBottomHeight = 40;
                    }
                })
            }
        });
    },
    methods: {
        tabbarChange(path) {
            uni.switchTab({
                url: path
            })
        }
    }
};